/*
 * Wind.m
 * This file is part of WX
 *
 * Copyright 2010-2013 Jason Coulls. All Rights Reserved.
 *
 * is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, version 2 of the License.
 *
 * is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with . If not, see <http://www.gnu.org/licenses>.
 */

#import "Wind.h"

@implementation Wind
@synthesize reading;
@synthesize speedScale;
@synthesize directionDegrees;

-(id) init
{
    self = [super init];
    //Create a default wind instance.
    self.speedScale = kSPEEDKMH;
    self.reading = 0;
    self.directionDegrees=0;
    return self;
}

#pragma mark - Conversion Routines

-(double) speedInMPH
{
    double returnValue = 0;
    
    if (speedScale == kSPEEDMPH) {
        //Already MPH, so return current value.
        returnValue = reading;
        
    } else if (speedScale == kSPEEDKMH) {
        //Convert KMH to MPH
        returnValue = reading * 0.621371;
        
    } else if (speedScale == KSPEEDKNOTS) {
        //Convert Knots to MPH
        returnValue = reading * 1.15077944802;
        
    }
    
    return returnValue;
}

-(double) speedInKMH
{
    double returnValue = 0;
    
    if (speedScale == kSPEEDMPH) {
        //Convert MPH to KMH
        returnValue = reading * 1.60934;
        
    } else if (speedScale == kSPEEDKMH) {
        //Already KMH, so return current value.
        returnValue = reading;
        
    } else if (speedScale == KSPEEDKNOTS) {
        //Convert Knots to KMH
        returnValue = reading * 1.852;
        
    }
    
    return returnValue;

}


-(double) speedInKnots
{
    double returnValue = 0;
    
    if (speedScale == kSPEEDMPH) {
        //Convert MPH to Knots
        returnValue = reading * 0.868976;
        
    } else if (speedScale == kSPEEDKMH) {
        //Convert KMH to Knots.
        returnValue = reading * 0.539957;
        
    } else if (speedScale == KSPEEDKNOTS) {
        //Already Knots, so return current value
        returnValue = reading;
        
    }
    
    return returnValue;

}


@end
